#ifndef FRACTIONINTERPRETER_H
#define FRACTIONINTERPRETER_H

#include <QObject>
#include <QtDebug>

#include "syntaxanalyser.h"
#include "getfractiondialog.h"

class FractionInterpreter : public QObject
{
	Q_OBJECT

public:
	FractionInterpreter(QObject *parent = 0);
	FractionInterpreter(QString &code, QObject *parent = 0);
	~FractionInterpreter();

	SyntaxAnalyser* syntax();

	void setSource(QString &source);
	SyntaxTreeNode* tree();

	bool ExecuteBlock(SyntaxTreeNode* node);
	bool ExecuteStatments(SyntaxTreeNode* node);	
	bool ExecuteAssigment(SyntaxTreeNode* node);	
	bool ExecutePrintVarCall(SyntaxTreeNode* node);
	bool ExecuteIfStatment(SyntaxTreeNode* node);
	bool ExecuteWhileStatment(SyntaxTreeNode* node);	

	SymbolType ExecuteRelOp(SyntaxTreeNode* node);
	SymbolType ExecuteMinorOp(SyntaxTreeNode* node);
	SymbolType ExecutePriorOp(SyntaxTreeNode* node);	

	Value ExecuteExpression(SyntaxTreeNode* node);
	Value ExecuteSimpleExpression(SyntaxTreeNode* node);
	Value ExecuteMinorFactor(SyntaxTreeNode* node);
	Value ExecutePriorFactor(SyntaxTreeNode* node);
	Value ExecuteProcedureCall(SyntaxTreeNode* node);
	Value ExecuteGetVarCall(SyntaxTreeNode* node);

	Value ExecuteID(SyntaxTreeNode* node);

private:
	void setData();
	qint32 startProcedure(Procedure p);
	Value endProcedure(qint32 id);


private:
	SyntaxAnalyser* _syntax;

	ScopeTemplate global;			// przestrzen globalna zmiennych
	QList<ScopeTemplate> scopes;	// przestrzen aktualna (ostatnia aktualna)	

	SyntaxTreeNode* root;			// wskaznik na glowny blok	
};

#endif // FRACTIONINTERPRETER_H
